package com.itqf.beanfactory;

import com.itqf.controller.IndexController;
import com.itqf.service.IndexService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * projectName: springmvcgp8
 *
 * @author: 赵伟风
 * time: 2021/8/9 11:39
 * description:
 */
public class UseFactory {



    public static void main(String[] args) {


        //1.c容器
        ClassPathXmlApplicationContext webFactory = new ClassPathXmlApplicationContext("spring-web.xml");
        ClassPathXmlApplicationContext serviceFactory = new ClassPathXmlApplicationContext("spring-service.xml");


        //2.获取
        IndexController bean = webFactory.getBean(IndexController.class);
        System.out.println("bean = " + bean);



        IndexService bean1 = serviceFactory.getBean(IndexService.class);
        System.out.println("bean1 = " + bean1);


        //3.容器继承
        webFactory.setParent(serviceFactory);

        //设置父容器以后重新加载和刷新
        webFactory.refresh();

        System.out.println(webFactory.getBean(IndexService.class));
        System.out.println(serviceFactory.getBean(IndexController.class));

    }


}
